﻿var current = 1;
var isPreviousEventComplete = true;
$(document).ready(function ()//
{
    $("body").on("click", ".lnkShowChapters", lnkShowChapters_click);
    $(window).scroll(loadContent_OnScroll);
});

function lnkShowChapters_click() {
    var story = "#" + $(this).attr("story");
    $(story).slideToggle("slow");
}

function loadContent_OnScroll(e) {

    if ($(document).height() - 50 <= $(window).scrollTop() + $(window).height())//
    {
        if (isPreviousEventComplete) {
            isPreviousEventComplete = false;
            var Controller = $(this).attr('Controller');
            var Index = $(this).attr('Index');
            $.AjaxMVC(
            {
                Url: "/Story/Pager",
                Json: false,
                Dados: "Index=" + (current + 1),
                Sucesso: function () {
                    isPreviousEventComplete = true;
                    current = current + 1;
                }
            });
        }
    }
}
